import { defineConfig } from "vite"
import vue from "@vitejs/plugin-vue"
import path from "path"
// ⾃动导⼊
import AutoImport from "unplugin-auto-import/vite"
import Components from "unplugin-vue-components/vite"
import { ElementPlusResolver } from "unplugin-vue-components/resolvers"
import ElementPlus from "unplugin-element-plus/vite" //自动引入样式，否则弹窗消息无样式
// https://vitejs.dev/config/
export default defineConfig({
  resolve: {
    alias: [
      {
        find: "@",
        replacement: path.resolve(__dirname, "src") //当前模块所在目录的绝对路径。
      }
    ]
  },
  plugins: [
    vue(),
    AutoImport({
      // 自动导入api
      imports: ["vue", "vue-router", "pinia"],
      resolvers: [ElementPlusResolver()],
      eslintrc: { enabled: false } // ts自动导入会报错，所以给eslint生产的配置 只需要一次true运行后改为false，自动生成.eslintrc-auto-import.json
      // dts: "src/auto-import.d.ts" // ⽣成的全局变量放到此⽬录下
    }),
    Components({
      //  解析组件
      resolvers: [ElementPlusResolver()],
      // 这里的组件可以自动加载
      dirs: [
        "src/components",
        "src/layout/components",
        "src/views/**/components"
      ]
    }),
    ElementPlus({}) // 导入样式 不需要引入
  ],
  css: {
    preprocessorOptions: {
      scss: {
        api: "modern-compiler" //or 'modern'，使用最新api
      }
    }
  },
  server: {
    proxy: {
      "/dev-api": {
        target: "http://localhost:3000",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/dev-api/, "/api")
      }
    }
  }
})
